<?php
date_default_timezone_set("Asia/Shanghai");//设置默认的时区
//数据为空时函数
function EofInfo($E_info){
	echo ("<br><br><div align='center' style='color:red;'>Sorry，暂无[".$E_info."]信息!</div>");
}
#'"\过滤

function saddslashes($string) {
//$string = stripslashes($string);
$string = str_replace("'","&#039;",$string);
$string = str_replace('"','&quot;',$string);
return $string;
}
function _get($string){
    return isset($string) ? filter_input(INPUT_POST,'name',FILTER_SANITIZE_SPECIAL_CHARS) : isset($string) ? filter_input(INPUT_POST,'name',FILTER_SANITIZE_SPECIAL_CHARS) : '';

}
function addSpecialChars($string) {
/*$string = htmlspecialchars($string);*/
$string = str_replace("&#039;","'",$string);
$string = str_replace('&quot;','"',$string);
return $string;
}
//过滤HTML代码

function replaceHtmlAndJs($document){

   $document = trim($document);

   if(strlen($document) <= 0){

     return $document;

   }

   $search = array ("'<script[^>]*?>.*?</script>'si",  // 去掉 javascript

                  "'<[\/\!]*?[^<>]*?>'si",             // 去掉 HTML 标记

                  "'([\r\n])[\s]+'",                   // 去掉空白字符

                  "'&(quot|#34);'i",                   // 替换 HTML 实体

                  "'&(amp|#38);'i",

                  "'&(lt|#60);'i",

                  "'&(gt|#62);'i",

                  "'&(nbsp|#160);'i"

                  );

				   

   $replace = array ("","","\\1", "\"", "&", "<", ">", " ");



   return @preg_replace_callback ($search, $replace, $document);

}


//===显示所有分类====
//==parentID是父目录ID==
//==Table是数据库表格==
//==Mcataid被选中的ID号==
//==Check_Xia显示的目录深度 如：4  则显示到第三级目录==
function ShowSelect($parentID,$Table,$Mcataid,$Check_Xia,$Check_Recursion)
{

    $sql_Sel="select * FROM `".$Table."` where CatalogParentId = ".$parentID." order by SortId asc";
    $conn = new Mysql();
    $row=$conn->getAll($sql_Sel);
    foreach($row as $k=>$rs_Sel)
    {
        if($Check_Xia > $rs_Sel["Mlevel"])
        {
            $M_title=$rs_Sel["title"];
            $tempcataStr="<option value=\"".trim($rs_Sel["id"])."\"";
            if($rs_Sel["id"]==$Mcataid){
                $tempcataStr = $tempcataStr." selected";
            }
            $tempcataStr = $tempcataStr.">";
            $tempcataStr = $tempcataStr."&nbsp;&nbsp;";
            $tempcataStr .= str_repeat("&nbsp;-",$rs_Sel["Mlevel"]-1);
            $tempcataStr = $tempcataStr."&nbsp;".trim($rs_Sel["title"])."</option>" ;

            echo  $tempcataStr;

            if ($Check_Recursion == true){
                ShowSelect($rs_Sel["id"],$Table,$Mcataid,$Check_Xia,$Check_Recursion);
            }
        }
    }
}

//展示关键字
function showhot_word($hot_key)
{
	if($hot_key !="")
	{
		$s_h = explode(",",$hot_key);
		for($i=0;$i<=count($s_h);$i++)
		{
			if($s_h[$i] !="")
			{
				echo "<li><a href=\"plist.php?areas=".urlencode($s_h[$i])."\" target=\"_blank\">".$s_h[$i]."</a>&nbsp;</li>";
			}
		}
	}
}

//展示关键字
function showhot_word2($hot_key)
{
	if($hot_key !="")
	{
		$s_h = explode(",",$hot_key);
		for($i=0;$i<=count($s_h);$i++)
		{
			if($s_h[$i] !="")
			{
				echo "<li><a href=\"product.php?type=".urlencode($s_h[$i])."\" >".GetTitle($s_h[$i],"newscata_product")."</a></li>";
			}
		}
	}
}
//展示关键字
//获取菜单名称
function GetTitle($TypeID,$table){

    $TypeID=intval($TypeID);
    if($TypeID && is_numeric($TypeID)){
        $conn = new Mysql();
        $rs_gt = $conn->getRow("select title from `$table` where id='".$TypeID."'");
        if($rs_gt){
            $GetTitle = $rs_gt[0];
        }
    }
    return $GetTitle;
}
//产生随机码
function getRandoms($length) {
    $arr1 = range(0,9);
    $arr2 = range('a','z');
    $arr3 = range('A','Z');
    $pattern = array_merge($arr1,$arr2,$arr3);//合并数组

//    $pattern = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ";    //字符池
    $len = count($pattern) - 1;
    $key = "";

    for($i = 0; $i < $length; $i ++) {
        $key .= $pattern[mt_rand(0, $len)];//生成php随机数
    }
    return strtolower($key);
}
//产生随机码

//显示等级
function ShowGrade($grade)
{
	switch($grade)
	{
		case 1:
			return '普通会员';
			break;
		case 2:
			return '高级会员';
			break;
		case 3:
			return '黄金会员';
			break;
	}
}

//获取表单项目
function get_post()
{
	global $HTTP_POST_VARS;
	global $HTTP_GET_VARS;
	
	if(function_exists(array_merge)){
		$ArrPostAndGet=array_merge($HTTP_POST_VARS,$HTTP_GET_VARS);
	}else{
		foreach($HTTP_POST_VARS as $key=>$value){
		$ArrPostAndGet[]=$value;
		}
		foreach($HTTP_GET_VARS as $key=>$value){
		$ArrPostAndGet[]=$value;
		}
	}	
	foreach($ArrPostAndGet as $key=>$value)
	{
		echo $key.':--------------'.$value.'<br>';
	}
}

//显示性别
function Showsex($sex)
{
	if($sex==0){return '先生';}else{return '女士';}
}

//is_4s是否
function is_4s($is_s)
{
	if($is_s==1){$flat = '<font color=red>是</font>';}else{$flat = '<font color=blue>否</font>';}
	return $flat;
}


//验证是否为空，为空则显示空。
function is_empty($this_va,$empty)
{
	if(isset($this_va))
	{
		return $this_va;
	}else{
		return $empty;
	}
}

//完美替换HTML标签
function pregstring( $str ){
$strtemp = trim($str);
$search = array(
"|'|Uis",
"|<script[^>]*?>.*?</script>|Uis", // 去掉 javascript
"|<[\/\!]*?[^<>]*?>|Uis",    // 去掉 HTML 标记
"'&(quot|#34);'i",      // 替换 HTML 实体
"'&(amp|#38);'i",
"|,|Uis",
"|[\s]{2,}|is",
"[&nbsp;]isu",
"|[$]|Uis",
);
$replace = array(
"`",
"",
"",
"",
"",
"",
" ",
" ",
" dollar ",
);
$text = preg_replace_callback($search, $replace, $strtemp);
//再次替换空格gbk
$text = str_replace("　","",$text);
return $text;
}



//==验证图片是否存在==
function GetPic($Gpic,$DefaultPic)
{
	if(!isset($Gpic)){
		$GetPic=$DefaultPic;
	}
	else
	{
		if(instr(Gpic,"://")>0)
		{
			$GetPic=$Gpic;
		}else{
			$GetPic="/pic/".$Gpic;
		}
	}
	return $GetPic;
}
//==验证图片是否存在==


//直接JS跳转函数
function GoLink($StrLink){
	echo "<script language='javascript'>";
	echo "window.location.href = '".$StrLink."';";
	echo "</script>";
	exit;
}
//直接JS跳转函数

//弹出提示然后返回
function OutErrorBack($Erinfo){
	echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
	echo "<script language='javascript'>";
	echo "alert('".$Erinfo."');";
	echo "history.back(-1);";
	echo "</script>";
	exit;
}
//弹出提示然后返回

//弹出提示然后跳转页面
function OutErrorGo($Erinfo,$StrLink){
	echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
	echo "<script language='javascript'>";
	echo "alert('".$Erinfo."');";
	echo "window.location.href = '".$StrLink."';";
	echo "</script>";
	exit;
}
//弹出提示然后跳转页面

//显示替换
function Replace($str){
	$str=str_replace('\"','"',$str);
	$str=str_replace("\'","'",$str);
	$Replace = $str;
	return $Replace;
}
//显示替换

//显示NOW()函数
function now(){
	$now = date('Y-m-d H:i:s');
	return $now;
}

//显示date()函数
function Rdate(){
	$Rdate = date('Y-m-d');
	return $Rdate;
}

//显示time()函数
function Rtime(){
	$Rtime = date('H:i:s');
	return $Rtime;
}


//显示短日期函数
function short_time($NowTime){
 	$short_time = date("Y-m-d",strtotime($NowTime));
	return $short_time;
}

//本站特殊转化时间函数
function short_Mytime($NowTime){
 	$short_time = date("m-d",strtotime($NowTime));
	return $short_time;
}

function Check_s($C_str,$InfoType){
	if($C_str==$InfoType){
		$Check_s = " checked='checked'";
		return $Check_s;
	}
}

/*
替换数值函数，此函数也可以作为购物车关键函数。
*/
function car_exclude($car_id,$exclude)
{
	//当需要替换的数值为0时不操作。
	if($exclude==0){
		return $car_id;
	}else
	{
		//替换当前传递过来的数值
		$r_id = ','.$car_id.',';//将原字符串加','号以便于替换

		$r_id = str_replace(",".$exclude.",",",",$r_id);//替换字符串
		
		if(instr($r_id,",")==1)//当字符串第一个字符是','号时则去掉','号
		{
			$r_id = substr($r_id,1);//截取字符串
		}
		if(substr($r_id, -1, 1)==",")//当字符串末尾最后一个字符串是','号时。
		{
			$r_id = substr($r_id,0,strlen($r_id)-1);//截取字符串，将字符串末尾','去掉。
		}
		return $r_id;
	}
}

/*
替换前后两个','号
*/
function car_replace_fe($compid)
{
	if(instr($compid,",")==1)
	{
		$compid = substr($compid,1);
	}
	if(substr($compid, -1, 1)==",")//当字符串末尾最后一个字符串是','号时。
	{
		$compid = substr($compid,0,strlen($compid)-1);//截取字符串，将字符串末尾','去掉。
	}
	return $compid;
}




function DateDiff ($interval, $date1,$date2) { 
// 得到两日期之间间隔的秒数 
 $timedifference = strtotime($date2) - strtotime($date1); 
 
 switch ($interval) {  
 case "w": $retval = bcdiv($timedifference ,604800); break;
 case "d": $retval = bcdiv( $timedifference,86400); break;
 case "h": $retval = bcdiv ($timedifference,3600); break;
 case "n": $retval = bcdiv( $timedifference,60); break;
 case "s": $retval = $timedifference; break;
 }
 return $retval;
}

//防VBscript时间增加函数
function DateAdd($part, $n, $date)
{
 switch($part)
 {
  case "y": $val = date("H:i:s", strtotime($date ." +$n year")); break;
  case "m": $val = date("H:i:s", strtotime($date ." +$n month")); break;
  case "w": $val = date("H:i:s", strtotime($date ." +$n week")); break;
  case "d": $val = date("H:i:s", strtotime($date ." +$n day")); break;
  case "h": $val = date("H:i:s", strtotime($date ." +$n hour")); break;
  case "n": $val = date("H:i:s", strtotime($date ." +$n minute")); break;
  case "s": $val = date("H:i:s", strtotime($date ." +$n second")); break;
 }
 return $val;
}

//纯真版防VBscrips
function DateAddvb($interval, $number, $date) {
$date_time_array = getdate($date); 
$hours = $date_time_array["hours"]; 
$minutes = $date_time_array["minutes"]; 
$seconds = $date_time_array["seconds"]; 
$month = $date_time_array["mon"]; 
$day = $date_time_array["mday"]; 
$year = $date_time_array["year"]; 
switch ($interval) { 
case "yyyy": $year +=$number; break; 
case "q": $month +=($number*3); break; 
case "m": $month +=$number; break; 
case "y": 
case "d": 
case "w": $day+=$number; break; 
case "ww": $day+=($number*7); break; 
case "h": $hours+=$number; break; 
case "n": $minutes+=$number; break; 
case "s": $seconds+=$number; break; 
} 
$timestamp = mktime($hours ,$minutes, $seconds,$month ,$day, $year); 
return $timestamp;
} 


/*
获取数据信息个数
*/
function resuestC($table,$cond)
{
	$conn = new Mysql();
	$conn->query("select * from `$table` where ($cond)");
	$rc = @mysql_num_rows($conn->res);
	if($rc>0)
	{
		return $rc;
	}else{
		return 0;
	}
}

/*
*****************************
单篇信息展示
*/
function info($ginfoID)
{
	$ginfoID = intval($ginfoID);
	$sql = "select content from company_shop where id='$ginfoID'";
	$conn=new Mysql();
	$rsginfo = $conn->getRow($sql);
	if($rsginfo)
	{
		return $rsginfo["content"];
	}
	
}
/*
*****************************
单篇信息展示
*/
function infoad($ginfoID,$juese)
{
	$ginfoID = intval($ginfoID);
	//dbOpen();
	$sql = "select ".$juese." from company_shop where id='$ginfoID'";
	$conn=new dbo();
	$conn->query($sql);
	$rsginfo = mysql_fetch_row($conn->res);
	if($rsginfo)
	{
		return $rsginfo[0];
	}
	
}

//栏目下级分类显示，横向显示
function showmenu($TypeBig,$xia_t,$oplink,$table)
{
	$TypeBig = intval($TypeBig);
	$conn = new Mysql();
	$conn->query("select id,title from $table where CatalogParentId = '$TypeBig' order by Sortid asc");
	while($rsginfo =@mysql_fetch_array($conn->res))
	{	
		if (instr(','.$xia_t.',',','.$rsginfo["id"].',')>0){
			echo "<a href='$oplink?type=".$rsginfo["id"]."' style=color:#FF6600;><b>".$rsginfo["title"]."</b></a>&nbsp;&nbsp;";
		}else{
			echo "<a href='$oplink?type=".$rsginfo["id"]."'>".$rsginfo["title"]."</a>&nbsp;&nbsp;";
		}
		
	}
	
}

//栏目下级分类显示，横向显示


/*
	信息打开页面程序
*/
function Info_Open()
{
	$id=intval($_REQUEST["id"]);
	if($id=="" || !is_numeric($id)){
		OutErrorBack("错误，请返回！");
	}else{
		$conn = new Mysql();		
		$conn->query("select id,title,content,adate,author,Linkcount,type from news_shop where id = '$id'");
		$rs = @mysql_fetch_row($conn->res);
		if($rs)
		{
			@mysql_query("update news_shop set Linkcount = Linkcount + 1 where id = '$id'");
			$title = $rs[1];
			$content = $rs[2];
			$adate = short_time($rs[3]);
			$author = $rs[4];
			$Linkcount = $rs[5]+1;
			$type1 = $rs[6];
			$showNextDate = $rs[3];
		}   
		echo '<div class="n_title">'.$title.'</div>';
		echo '<div class="n_suptime">发布时间：'.$adate.'</div>';
		echo ' <div class="n_content">'.ShowPage($content).'</div>';	
/*		echo "<div class=\"show_next\">";
			ShowNext($id,$type1,"view.php",$showNextDate);
		echo "</div>";*/
	}
}



//下一篇、上一篇
function ShowNext($SN_ID,$SN_Type,$SN_link,$news_adate)
{
	global $InfoProperties;
	$conn = new Mysql();
	//==判断显示出上一篇文章
	$conn->query("select id,title,adate,type from news_shop where adate>'".$news_adate."' and Type='".$SN_Type."' order by adate asc");
	$rs_Up =@mysql_fetch_array($conn->res);
	if(!$rs_Up)
	{
		echo $InfoProperties[6].'<br>';
	}else{
		echo $InfoProperties[7]."<a href=\"$SN_Link?id=$rs_Up[0]\">$rs_Up[1]</a><br>";
	}
	
	//==判断显示出下一篇文章==
	$conn->query("select id,title,adate,type from news_shop where adate< '".$news_adate."' and Type='".$SN_Type."' order by adate desc");
	$rs_Down =@mysql_fetch_array($conn->res);
	if(!$rs_Down)
	{
		echo $InfoProperties[8].'<br>';
	}else{
		echo $InfoProperties[9]."<a href=\"$SN_Link?id=$rs_Down[0]\">$rs_Down[1]</a><br>";
	}
}
//下一篇、上一篇

/*
处理有翻页标签的函数
*/
function ShowPage($newscontent)
{
	//获取当前URL地址以及参数
	$action = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
    $query = explode('&', $_SERVER['QUERY_STRING']);
	if(count($query)>0){
		for($i=0;$i<count($query);$i++)
		{
			$a = explode("=",$query[$i]);
			if(strcmp ("page",$a[0]) <> 0)
			{			
				$temp .= $a[0] . "=" . $a[1] . "&";
			}
		}
	}
	//获取当前URL地址以及参数

	if(instr($newscontent,'$$分页$$')==0)
	{
		echo $newscontent;
	}else{
		$S_N_p = explode('$$分页$$' , $newscontent);//此处为单引号，双引号会被认为是变量
				
		if(isset($_GET["page"])){
			$page = intval($_GET["page"]);
		}else{
			$page = 1;
		}
		if($page>count($S_N_p)){
			$page = count($S_N_p);
		}
		echo $S_N_p[$page-1];
		

			for($i=0;$i<count($S_N_p);$i++)
			{	
				$j = $i +1;
				if($j == $page)
				{
					echo "<font class=visited>$j</font>&nbsp;&nbsp;";
				}else{
					echo "<a href=".$action."?".$temp."page=$j>$j</a>&nbsp;&nbsp;";
				}
			}

	}
}

/*
instrrev()函数
从VBScript转换到PHP的InStrRev函数
从末尾查找，然后返回字符串所在位置.
*/
function instrrev($n,$s){ 
  $x=strpos(chr(0).strrev($n),$s)+0; 
  return (($x==0) ? 0 : strlen($n)-$x+1);
}


//删除单个文件
function ImgDelpic($dpic,$del_folder)
{
	if(instr($dpic,"://")==0)
	{
		$file = $del_folder.$dpic;
		//允许删除pic和images_1中的文件
		if (instr($file,"pic")>0 || instr($file,"images_1")>0 || instr($file,"carpic")>0)
		{
			if(file_exists($file))
			{
				@unlink($file); //删除文件
			}
		}
	}
}
//删除单个文件

//批量判断删除图片程序
function ImgDel($Oldpic,$NowPic,$Pic_path)
{
//$Pic_path是关键字段，在php中路径是比较重要的。
//函数操作时需要对文件路径做好设置 如：/images_1/ == ../images_1/ 
	$O_P_A = explode(",",$Oldpic);
	for($i=0;$i<=count($O_P_A);$i++)
	{	
		if(instr($O_P_A[$i],'://')==0 && $O_P_A[$i] != "")
		{	
			//判断现在的图片是否存在老地址中
			if(instr($NowPic,$O_P_A[$i])==0)
			{
				//echo $O_P_A[$i].'<br>';
				ImgDelpic($O_P_A[$i],$Pic_path);
			}
		}
	}
}
//批量判断删除图片程序

//地址转化，适用于修改页面后跳转回上一个操作页面。
function ReturnUrlGo($R_url,$R_tpye)
{
	if($R_tpye==1)
	{
		$R_url=str_replace("&","{|}",$R_url);
	}
	elseif($R_tpye=0)
	{
		$R_url=str_replace("{|}","&",$R_url);
	}
	$ReturnUrlGo=$R_url;
	return $ReturnUrlGo;
}
//地址转化，适用于修改页面后跳转回上一个操作页面。

//检测是否被选择高亮显示
function Check_color($Check_ID,$Type_2)
{
     $Type_2=(int)$Type_2;
	 
	 if ($Check_ID == $Type_2)
	 {
	 	$Check_color="font-weight:bold;color:#FF3300;";	
	 }
	 return $Check_color;
}

//获取栏目自己分类程序
//根据修改的数据库结构进行SQL查询。
//因为添加了一个Myrootid字段，该字段在rootid的基础上添加了“,”号区别，便于sql的查找。
//以下sql语句查询也可以写成"Myrootid like '%,8,%' "这样的形式,在运用其他数据中可以这样写。
//如果是ACCESS数据库用instr(Myrootid,',".$Get_ID.",')>0，如果是Mysql用Myrootid like '%,".$Get_ID.",%'。
function GetSqlSuper($Get_ID,$GetTable){
	if(isset($Get_ID))
	{
		$GetSqlSuper=$Get_ID;
		$conn = new Mysql();
		$conn->query("select ID from `$GetTable` where instr(Myrootid,',".$Get_ID.",')>0 order by id asc");
		$rs_Gs =@mysql_fetch_array($conn->res);
		if($rs_Gs){
			while($rs_Gs =@mysql_fetch_array($conn->res)){
				$GetSqlSuper .= ",".$rs_Gs[0];
			}
		}
		return $GetSqlSuper;
	}else{
		return 0;
	}
}
//获取栏目自己分类程序

//获取任意表中单独数据函数
//0代表string
//1其他是bool
function Request_table($files,$table,$fid){
	$fid = intval($fid);
	$conn = new Mysql();
    $rs_QT=$conn->getOne("select ".$files." from ".$table." where id='".$fid."'");

	if($rs_QT){
		$var_str=$rs_QT[0];
		return $var_str;
	}
}
//获取任意表中单独数据函数

function Request_fildes($files,$table,$fid){

    $conn = new Mysql();
    $rs_QT=$conn->getRow("select ".$files." as rtitle from `".$table."` where ".$fid."");


		$var_str=$rs_QT["rtitle"];
		return $var_str;

}
function Request_fildes_count($files,$table,$fid){

    $conn = new Mysql();
    $rs_QT=$conn->getRow("select ".$files." from `".$table."` where ".$fid."");


    $var_str=$rs_QT["nums"];
    return $var_str;

}
//获取任意表中单独数据函数

/**  
 *  将一个字串中含有全角的数字字符、字母、空格或'%+-()'字符转换为相应半角字符  
 *  
 * @access  public  
 * @param   string       $str         待转换字串  
 *  
 * @return  string       $str         处理后字串  
 */  
function make_semiangle($str)
{   
    $arr = array('０' => '0', '１' => '1', '２' => '2', '３' => '3', '４' => '4',   
                 '５' => '5', '６' => '6', '７' => '7', '８' => '8', '９' => '9',   
                 'Ａ' => 'A', 'Ｂ' => 'B', 'Ｃ' => 'C', 'Ｄ' => 'D', 'Ｅ' => 'E',   
                 'Ｆ' => 'F', 'Ｇ' => 'G', 'Ｈ' => 'H', 'Ｉ' => 'I', 'Ｊ' => 'J',   
                 'Ｋ' => 'K', 'Ｌ' => 'L', 'Ｍ' => 'M', 'Ｎ' => 'N', 'Ｏ' => 'O',   
                 'Ｐ' => 'P', 'Ｑ' => 'Q', 'Ｒ' => 'R', 'Ｓ' => 'S', 'Ｔ' => 'T',   
                 'Ｕ' => 'U', 'Ｖ' => 'V', 'Ｗ' => 'W', 'Ｘ' => 'X', 'Ｙ' => 'Y',   
                 'Ｚ' => 'Z', 'ａ' => 'a', 'ｂ' => 'b', 'ｃ' => 'c', 'ｄ' => 'd',   
                 'ｅ' => 'e', 'ｆ' => 'f', 'ｇ' => 'g', 'ｈ' => 'h', 'ｉ' => 'i',   
                 'ｊ' => 'j', 'ｋ' => 'k', 'ｌ' => 'l', 'ｍ' => 'm', 'ｎ' => 'n',   
                 'ｏ' => 'o', 'ｐ' => 'p', 'ｑ' => 'q', 'ｒ' => 'r', 'ｓ' => 's',   
                 'ｔ' => 't', 'ｕ' => 'u', 'ｖ' => 'v', 'ｗ' => 'w', 'ｘ' => 'x',   
                 'ｙ' => 'y', 'ｚ' => 'z',   
                 '（' => '(', '）' => ')', '〔' => '[', '〕' => ']', '【' => '[',   
                 '】' => ']', '〖' => '[', '〗' => ']', '“' => '[', '”' => ']',   
                 '‘' => '[', '’' => ']', '｛' => '{', '｝' => '}', '《' => '<',   
                 '》' => '>',   
                 '％' => '%', '＋' => '+', '—' => '-', '－' => '-', '～' => '-',   
                 '：' => ':', '。' => '.', '、' => ',', '，' => '.', '、' => '.',   
                 '；' => ',', '？' => '?', '！' => '!', '…' => '-', '‖' => '|',   
                 '”' => '"', '’' => '`', '‘' => '`', '｜' => '|', '〃' => '"',   
                 '　' => ' ');   
    return strtr($str, $arr);   
}




//获取文件大小
function GetSize($filename)
{
   $size = filesize($filename);
   $count = 0;
   $format = array("B","KB","MB","GB","TB","PB","EB","ZB","YB");
   while(($size/1024)>1 && $count<8)
   {
       $size=$size/1024;
       $count++;
   }
   $return = number_format($size,0,'','.')." ".$format[$count];
   return $return;
}
//获取文件大小


/* 
Utf-8、gb2312都支持的汉字截取函数 
killword(字符串, 截取长度, 开始长度, 编码); 
编码默认为 utf-8 
开始长度默认为 0 
*/
function killword($string, $sublen, $start = 0, $code = 'UTF-8') 
{ 
    if($code == 'UTF-8') 
    { 
        $pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/"; 
        preg_match_all($pa, $string, $t_string); 
 
        if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen))."..."; 
        return join('', array_slice($t_string[0], $start, $sublen)); 
    } 
    else 
    { 
        $start = $start*2; 
        $sublen = $sublen*2; 
        $strlen = strlen($string); 
        $tmpstr = ''; 
 
        for($i=0; $i< $strlen; $i++) 
        { 
            if($i>=$start && $i< ($start+$sublen)) 
            { 
                if(ord(substr($string, $i, 1))>129) 
                { 
                    $tmpstr.= substr($string, $i, 2); 
                } 
                else 
                { 
                    $tmpstr.= substr($string, $i, 1); 
                } 
            } 
            if(ord(substr($string, $i, 1))>129) $i++; 
        } 
        if(strlen($tmpstr)< $strlen ) $tmpstr.= "..."; 
        return $tmpstr; 
    } 
}//截取字符串长度代码

//获取哦栏目上一级菜单ID或者名称
//$TypeID类别ID号，$SType显示类型，0是显示标题，1是表示显示ID号。
function GetBigTop($TypeID,$SType,$table){
    $GetBigTop=$TypeID;
    if($TypeID && is_numeric($TypeID)){
        $conn= new Mysql();
        $rs_gtop = $conn->getRow("select id,title,Mlevel,rootid from `$table` where id='".$TypeID."'");
        if($rs_gtop){
            if($rs_gtop[2]>1){	//当分类深度大于1时说明属于子级分类.
                $T_split=explode(",",$rs_gtop[3]);	//分割rootid
                $id_menu=$T_split[$rs_gtop[2]-2];	//得到上一级ID号
                $id_f = $T_split[0];//第一大类
                if($SType==1){
                    $GetBigTop = $id_menu;
                }else{
                    $GetBigTop = $id_f;
                }
            }
        }
    }
    return $GetBigTop;
}

#***********************************
//管理后台翻页函数
//后台翻页也可以用于前台翻页，不同的是跳转翻页变成下拉形式.
function Controlnews($num_cnt,$page_cnt,$page,$table_style,$font_style)
{
//翻页处理总函数  $num_cnt总记录数  $page_cnt总页数  $page当前页码	
    $action = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
    $query = explode("&", $_SERVER['QUERY_STRING']);

	if(count($query)>=1){
		for($i=0;$i<count($query);$i++)
		{
			$a = explode("=",$query[$i]);
			if(strcmp ("page",$a[0]) <> 0)
			{			
				$temp .= $a[0] . "=" . $a[1] . "&";
			}
		}
	}
	echo "<div class=\"PageProgram\">\n";	
	if($page<=1)
	{
		echo "首页&nbsp;\n";
		echo "上一页&nbsp;\n";
	}else{
		echo "<a href=".$action."?".$temp."page=1 id='page_t'>首页</a>&nbsp;\n";
		echo "<a href=".$action."?".$temp."page=".($page-1)." id='page_t'>上一页</a>&nbsp;\n";
	}	
    if($page>=$page_cnt)
	{
		echo "下一页&nbsp;\n";
		echo "尾页&nbsp;\n";
	}
    else
    {
		echo "<a href=".$action."?".$temp."page=".($page+1)." id='page_t'>下一页</a>&nbsp;\n";
		echo "<a href=".$action."?".$temp."page=".$page_cnt." id='page_t'>尾页</a>&nbsp;\n";     
	}
	echo "&nbsp;页次: ".$page."/".$page_cnt;
	echo "&nbsp;共有".$num_cnt."条信息\n";
	global $page_size;
	echo "&nbsp;每页共<span class='shine'>".$page_size."</span>条信息\n";
	echo " 转到:";
	echo "<select name=s onChange='window.location.href=this.options[this.selectedIndex].value;admin_id.options[0].selected=true'>";
	for($i=1;$i<=$page_cnt;$i++)
	{
		if($page==$i)
		{
			echo "<option value='".$action."?".$temp."page=".$i."' selected>".$i."</option>";
		}else
		{
			echo "<option value='".$action."?".$temp."page=".$i."'>".$i."</option>";
		}
	}
	echo "</select>";
	echo "</div>";
}
#***********************************
//管理后台翻页函数

function Pagefenye($num_cnt,$page_cnt,$page)
{
//翻页处理总函数  $num_cnt总记录数  $page_cnt总页数  $page当前页码
    $action = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
    $query = explode("&", $_SERVER['QUERY_STRING']);
    $temp="";
    if(count($query)>=1){
        for($i=0;$i<count($query);$i++)
        {
            $a = explode("=",$query[$i]);

            if(strcmp("page",$a[0]) <> 0&& $a[0]!="")
            {
                $temp .= $a[0] . "=" . $a[1] . "&";
            }
        }
    }
    echo "<ul class=\"pagination\">\n";
    if($page<=1)
    {
        echo '<li class=""><a class="" href="#">首页</a></li>';
        echo '<li class=""><a class="" href="#">上一页</a></li>';

    }else{
        echo "<li class=\"\"><a href=".$action."?".$temp."page=1 id='page_t'>首页</a></li>";
        echo "<li><a href=".$action."?".$temp."page=".($page-1)." id='page_t'>上一页</a></li>";
    }
    $mypage=1;

    if(isset($_GET['page'])){
        $mypage=$_GET['page'];
    }

    if($page_cnt>10){

        if($mypage+9>=$page_cnt){
            $pc=$page_cnt;
        }else{
            $pc=$mypage+9;
        }
        for ($i=$mypage; $i<=$pc; $i++) {
            if($i==$mypage){
                $sty=' class="active"';
            }else{
                $sty=' class="disabled" ';
            }
            echo '<li ><a href='.$action.'?'.$temp.'page='.$i.' '.$sty.''.$i.'</a></li>';
        }}else{
        for ($i=1; $i<=$page_cnt; $i++) {
            if($i==$mypage){
                $sty=' class="active"';
            }else{
                $sty=' class="disabled" ';
            }
            echo '<li ><a href='.$action.'?'.$temp.'page='.$i.' '.$sty.'> '.$i.'</a></li>';
        }
    }


    if($page>=$page_cnt)
    {
        echo '<li class=""><a class="" href="#">下一页</a></li>';
        echo '<li class=""><a class="" href="#">尾页</a></li>';
    }
    else
    {
        echo "<li><a href=".$action."?".$temp."page=".($page+1)." id='page_t'>下一页</a></li>";
        echo "<li><a href=".$action."?".$temp."page=".$page_cnt." id='page_t'>尾页</a></li>";
    }

    echo "</ul>";
}
function html($string)
{
	$string = str_replace("<","&lt;",$string);
	$string = str_replace(">","&gt;",$string);
	$string = str_replace(chr(13),"<br>",$string);
	$string = str_replace(chr(32),"&nbsp;",$string);
	return $string;
}


	
?>